{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "f332ba28",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "label type is 00 which is a six byte label\n",
      "start is  0b1\n",
      "stop is  0b0\n",
      "label type is 0b00\n",
      "total length field condition has been met and total length value is 0xeeee\n",
      "protocol type field condition has been met and protocol type value is 0x86dd\n",
      "six byte label condition has been met and the label is 0xad55ad55ad55\n",
      "GSE data is 0x8aaaeeee86ddad55ad55ad55\n",
      "GSE data size is 96\n",
      "Dummy frame set here?\n",
      "inside produce_BBFRAME method\n",
      "inside produce_PLHEADER method\n",
      "the modulation is qpsk\n",
      "the code rate is 1/4\n",
      "[1 1 1 1 1 1]\n",
      "dummy PLFRAME normal size [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]\n",
      "dummy PLFRAME short size [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "QPSK 1/4 PLFRAME normal size [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "QPSK 1/3 PLFRAME short size [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 0 0 0 1 1 1 1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1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "[1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "the codeword is a boolean array [False False False False False False False False False False False False\n",
      " False False False False  True  True  True  True  True  True  True  True\n",
      "  True  True  True  True  True  True  True  True]\n",
      "the codeword as array type int [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]\n",
      "the codeword is array type int but as a list [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n"
     ]
    },
    {
     "ename": "TypeError",
     "evalue": "'int' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-31-eb600a5ba9cd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m    603\u001b[0m \u001b[0;31m#print(b\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    604\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mproduce_BBFRAME\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 605\u001b[0;31m \u001b[0mPLHEADER\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mproduce_PLHEADER\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'short'\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m'yes'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'qpsk'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'1/4'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    606\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"The PLHEADER is\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mPLHEADER\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    607\u001b[0m \u001b[0mb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrandomize_PLFRAME\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;32m<ipython-input-31-eb600a5ba9cd>\u001b[0m in \u001b[0;36mproduce_PLHEADER\u001b[0;34m(self, FECFRAME_length, pilots, XFECFRAME_modulation, FEC_rate)\u001b[0m\n\u001b[1;32m    546\u001b[0m                 \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mrange\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m32\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    547\u001b[0m                         \u001b[0;31m#print(\"this is element\", (codeword_int_list[0][i]))\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 548\u001b[0;31m                         \u001b[0mcodeword_bitarray\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcodeword_int_list\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    549\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    550\u001b[0m                 \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"codeword_bitarray is\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcodeword_bitarray\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mTypeError\u001b[0m: 'int' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "# %load GSE_Packet_Creation.py\n",
    "#this is what was recommended by mossman\n",
    "from bitstring import BitArray, BitStream\n",
    "\n",
    "#array class from numpy\n",
    "from numpy import array\n",
    "from numpy import transpose\n",
    "from numpy import matmul\n",
    "\n",
    "#A more OO way to handle this is to build a state machine using the state pattern.\n",
    "\n",
    "#Handling incoming raw data is parsing where state machines provide an elegant solution \n",
    "#(you will have to choose between elegant and performance)\n",
    "\n",
    "#You have a data buffer to process, each state has a handle buffer method that parses \n",
    "#and processes their part of the buffer (if already possible) and sets the next state based on the content.\n",
    "\n",
    "#If you want to go for performance, you still can use a state machine, but leave out the OO part.\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n",
    "# GSE Packet creation station starts here\n",
    "#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n",
    "\n",
    "#Baseband frame information\n",
    "#should *this* be an object?\n",
    "#N1 is the number of bytes until the end of the Base Band Frame. \n",
    "#We know how long a Base Band Frame is, so start with that number\n",
    "#and count down. The current count goes in N1. \n",
    "N1 = 10\n",
    "\n",
    "\n",
    "#if start indicator == 0 and end indicator == 0 and label type indicator == 0\n",
    "# then there are four padding bits, and padding bytes? Confused. \n",
    "\n",
    "\n",
    "#Protocol Data Units are the things we want to encapsulate\n",
    "#maybe these are a bitstream but let's do BitArrays read from files first. \n",
    "#How about making it a random value every time we run the code when we find\n",
    "#both hemispheres of our derrieres with our hands\n",
    "\n",
    "#you still need a copy of the GSE standard in front of you to make much sense of this.\n",
    "#there is some documentation of the fields included in this code but it's a brief reference. \n",
    "\n",
    "default_start = '0b1'\n",
    "#start indicator\n",
    "\n",
    "default_stop = '0b0'\n",
    "#stop indicator\n",
    "\n",
    "default_label_type = '0b00'\n",
    "#label type indicator\n",
    "\n",
    "#The GSE Label Field is optional. \n",
    "#Depending on the Label Type Indicator of the GSE Header, \n",
    "#the Label field can have a length of 6 bytes, 3 bytes or be omitted.\n",
    "\n",
    "#00 6-byte label is present and shall be used for filtering\n",
    "#01 3-byte label is present and shall be used for filtering\n",
    "#10 Broadcast. No label field present. All Rx shall process this packet.\n",
    "#   This combination shall be used also in non-broadcast systems when \n",
    "#   no filtering is applied at Layer 2, but IP header processing is utilized.\n",
    "#11 Label re-use. No label field is present. All Rx shall reuse the label \n",
    "#   that was present in the previous Start or Complete GSE Packet of the \n",
    "#   same Base Band frame. This method is used for transmitting a sequence \n",
    "#   of GSE packets with the same label without repeating the label field. \n",
    "#   This value shall not be used for the first GSE packet in the frame. \n",
    "\n",
    "default_GSE_length = '0b101010101010'\n",
    "#This 12-bit field indicates the length, in bytes, of the GSE Packet \n",
    "#counted from the byte following this GSE Length field. The GSE Length \n",
    "#field allows for a length of up to 4096 bytes for a GSE Packet. \n",
    "#The GSE Length field points to the start of the following GSE Packet, \n",
    "#or to the end of the Data Field or start of the padding field if the \n",
    "#GSE packet is the last in the frame.\n",
    "\n",
    "default_fragment_ID = '0b01010101'\n",
    "#This is present when a PDU fragment is included in the GSE Packet, \n",
    "#while it is not present if Start_Indicator and End_Indicator are \n",
    "#both set to \"1\". All GSE Packets containing PDU fragments belonging \n",
    "#to the same PDU shall contain the same Frag ID. The selected Frag ID \n",
    "#shall not be re-used on the link until the last fragment of the PDU \n",
    "#has been transmitted. (see clause 4.3).\n",
    "\n",
    "default_total_length = '0b1110111011101110'\n",
    "#This field is present in the GSE Header carrying the first fragment \n",
    "#of a fragmented PDU. The 16-bit field carries the value of the total \n",
    "#length, defined as the length, in bytes, of the Protocol Type, Label \n",
    "#(6 byte Label or 3 byte Label), Extension Headers, and the full PDU. \n",
    "#The receiver shall perform a total length check after reassembly. It\n",
    "#may also use the total length information for pre-allocation of buffer \n",
    "#space. Although the length of a single GSE Packet\n",
    "#is limited to almost 4 096 bytes, larger PDUs are supported through \n",
    "#fragmentation, up to a total length of 65,536 bytes.\n",
    "#NOTE 2: Since the information in the total length field is intended \n",
    "#for use by higher layers in the reassembly process, the length of the \n",
    "#CRC_32 field is therefore not included in the Total_Length. \n",
    "\n",
    "default_protocol_type = '0b 1000 0110 1101 1101'\n",
    "#This 16-bit field indicates the type of payload carried in the PDU, \n",
    "#or the presence of a Next-Header. The set of values that may be \n",
    "#assigned to this field is divided into two ranges, similar to the \n",
    "#allocation of Ethernet and shall follow the rules described in [5]. The two ranges are:\n",
    "\t#Type 1: Next-Header Type field \n",
    "\t#Type 2: EtherType compatible Type Fields \n",
    "\t#EXAMPLE: 0x0800: IPv4 payload\n",
    "\t \t\t\t#0x86DD: IPv6 payload \n",
    "\n",
    "#default_label presence and length depends on the label type\n",
    "if default_label_type == '0b00':\n",
    "\tprint(\"label type is 00 which is a six byte label\")\n",
    "\tdefault_label = '0b101011010101010110101101010101011010110101010101'\n",
    "elif default_label_type == '0b01':\n",
    "\tprint(\"label type is 01 which is a three byte label\")\n",
    "\tdefault_label = '0b101011010101010101010101'\n",
    "elif default_label_type == '0b10':\n",
    "\tprint(\"label type is 10 which is broadcast.\")\n",
    "\tdefault_label = None\n",
    "elif default_label_type == '0b11':\n",
    "\tprint(\"label type is 11 which is reuse last label.\")\n",
    "\tdefault_label = None\n",
    "else:\n",
    "\tprint(\"label type was unrecognized.\")\n",
    "\tdefault_label = None\n",
    "\n",
    "\n",
    "\n",
    "#data_byte: These bytes shall contain a concatenation of any \n",
    "#extension header bytes, and the PDU data. The optional\n",
    "#extension header bytes shall be used to carry one or more \n",
    "#extension header(s). The extension header format is defined \n",
    "#by the ULE specification [5]. For further details on this field, \n",
    "#also see clause 4.2.4.\n",
    "#NOTE 3: N2 is the length of the encapsulated PDU or PDU fragment in bytes. \n",
    "\n",
    "\n",
    "zero_prefix = '0b00000'\n",
    "H_LEN = '0b001'\n",
    "#001 optional extension header length of 2 bytes\n",
    "#010 optional extension header length of 4 bytes\n",
    "#011 optional extension header length of 6 bytes\n",
    "#100 optional extension header length of 8 bytes\n",
    "#101 optional extension header length of 10 bytes\n",
    "\n",
    "H_TYPE = '0b11111111'\n",
    "#represents either one of 256 Mandatory Extension Headers or\n",
    "#represents one of 256 Optional Extension Headers\n",
    "\n",
    "default_extension_header_1 = zero_prefix+H_LEN+H_TYPE\n",
    "\n",
    "\n",
    "#default_extension_header_2 =\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "#CRC_32: This field is only present in a GSE Packet that carries \n",
    "#the last PDU fragment. This field shall be set as defined in clause 4.2.2. \n",
    "\n",
    "\n",
    "class GSE:\n",
    "\tdef __init__(self):\n",
    "\t\tstart = BitArray(default_start)\n",
    "\t\tprint(\"start is \", start)\n",
    "\t\tstop = BitArray(default_stop)\n",
    "\t\tprint(\"stop is \", stop)\n",
    "\t\tlabel_type = BitArray(default_label_type)\n",
    "\t\tprint(\"label type is\", label_type)\n",
    "\n",
    "\n",
    "\n",
    "\t\t#they have to exist before we can use them\n",
    "\t\tpadding = BitArray()\n",
    "\t\tfragment_ID = BitArray()\n",
    "\t\ttotal_length = BitArray()\t\n",
    "\t\tprotocol_type = BitArray()\t\n",
    "\t\tlabel = BitArray()\n",
    "\n",
    "\n",
    "\t\t\n",
    "\t\tif start == '0b0' and stop == '0b0' and label_type == '0b00':\n",
    "\t\t\tprint(\"padding condition has been met\")\n",
    "\n",
    "#N1 is the number of bytes until the end of the Base Band frame.\n",
    "#how do we get N1? Keep track of it with calculations?\n",
    "\t\t\tfor x in range(0, N1-1):{\n",
    "\t\t\tpadding.append('0b00000000')\n",
    "\t\t\t}\n",
    "\t\t\t\n",
    "\t\t\n",
    "\t\tGSE_length = BitArray(default_GSE_length)\n",
    "\t\t\n",
    "\t\t\n",
    "\t\tif start == '0b0' and stop == '0b0':\n",
    "\t\t\tfragment_ID = BitArray(default_fragment_ID)\n",
    "\t\t\tprint(\"fragment ID condition has been met and fragment ID value is\", fragment_ID)\n",
    "\t\t\n",
    "\t\tif start == '0b1' and stop == '0b0':\n",
    "\t\t\ttotal_length = BitArray(default_total_length)\n",
    "\t\t\tprint(\"total length field condition has been met and total length value is\", total_length)\n",
    "\t\t\n",
    "\t\tif start == '0b1':\n",
    "\t\t\tprotocol_type = BitArray(default_protocol_type)\n",
    "\t\t\tprint(\"protocol type field condition has been met and protocol type value is\", protocol_type)\n",
    "\t\t\tif label_type == '0b00':\n",
    "\t\t\t\tlabel = BitArray(default_label)\n",
    "\t\t\t\tprint(\"six byte label condition has been met and the label is\", label)\n",
    "\t\t\telif label_type == '0b01':\n",
    "\t\t\t\tlabel = BitArray(default_label)\n",
    "\t\t\t\tprint(\"three byte label condition has been met and the label is\", label)\n",
    "\n",
    "\n",
    "\t\tfixed_header = start+stop+label_type+GSE_length\n",
    "\n",
    "\t\tself.data = fixed_header+padding+fragment_ID+total_length+protocol_type+label\n",
    "\t\tself.size = len(self.data)\n",
    "\n",
    "#Encapsulated Packet Unit = GSE Packet\n",
    "class EPU:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = pack('!bb', 0xe, 0xf)\n",
    "\t\n",
    "\n",
    "#Baseband frame\n",
    "class BBF:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0,0,0,0,0,0,0,0,0,0]\n",
    "\t\t#demo data [0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0]\n",
    "\n",
    "#one of two topmost units that make GSE packets\n",
    "class PDU_manager:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\n",
    "\n",
    "\t\n",
    "\t\t\n",
    "#stores received PDU packets \n",
    "#Provides QoS and ACM support\n",
    "#ACM FIFO queues\n",
    "#three priority levels\n",
    "#each priority level has a different ACM mode\n",
    "class Scheduler_queue:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\n",
    "class EF_queue:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\t\n",
    "class AF_queue:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\n",
    "\t\n",
    "class BE_queue:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\t\n",
    "class ACM_updater:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\t\n",
    "class Priority_solver:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\n",
    "\t\n",
    "class Timeout_scheduler:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\n",
    "\t\n",
    "class Priority_scheduler:\n",
    "\tdef __init__(self):\n",
    "\t\tself.data = [0,0,0]\n",
    "\t\t#for example\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\n",
    "#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n",
    "# The EPU Manager is one of two top tier units in the block \n",
    "# diagram on page 19 of the GSE implementation guideline \n",
    "# specification from ETSI.\n",
    "# This block diagram is a very useful thing. Pages 19-22 are\n",
    "# in the repo for easy reference. \n",
    "# EPU_manager Makes baseband frames.\n",
    "# The other block is the PDU Manaager, which takes in protocol \n",
    "# Data Units and decides the adaptive coding and modulation \n",
    "# mapping, and then delivers things to the Scheduler Queues. \n",
    "#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n",
    "\n",
    "\n",
    "\n",
    "#Two PLFRAME configurations shall be possible:\n",
    "#* Without pilots.\n",
    "#* With pilots.\n",
    "#In this latter case a PILOT BLOCK shall be composed of P = 36 pilot symbols. \n",
    "#Each pilot shall be an un-modulated symbol, identified by I = (1/square root of 2), Q = (1/square root of 2).\n",
    "#The first PILOT BLOCK shall be inserted 16 SLOTs after the PLHEADER, the second \n",
    "#after 32 SLOTs and so on, as represented in figure 13. If the PILOT BLOCK \n",
    "#position coincides with the beginning of the next SOF, then the PILOT BLOCK is not transmitted.\n",
    "#The pilot presence/absence in VCM and ACM can be changed on a frame-by-frame basis.\n",
    "#W5NYV believes we should always have a pilot block. \n",
    "\n",
    "\n",
    "class EPU_manager:\n",
    "\tdef __init__(self):\n",
    "\t\tprint(\"Dummy frame set here?\")\n",
    "\tdef produce_BBFRAME(self):\n",
    "\t\tprint(\"inside produce_BBFRAME method\")\n",
    "\n",
    "\n",
    "\n",
    "\tdef randomize_PLFRAME(self):\n",
    "\t\tprint(\"inside randomize_PLFRAME method\")\n",
    "\t\t#Prior to modulation, each PLFRAME, excluding the PLHEADER, shall be randomized \n",
    "\t\t#for energy dispersal by multiplying the (I+jQ) samples by a complex randomization sequence (CI+jCQ):\n",
    "\n",
    "\n",
    "\n",
    "\tdef produce_PLHEADER(self, FECFRAME_length, pilots, XFECFRAME_modulation, FEC_rate):\n",
    "\t\t#kick out a PLHEADER by itself\n",
    "\t\t#The PLHEADER is intended for receiver synchronization and physical layer signalling.\n",
    "\t\t#NOTE: After decoding the PLHEADER, the receiver knows the PLFRAME duration and structure, \n",
    "\t\t#the modulation and coding scheme of the XFECFRAME, the presence or absence of pilot symbols.\n",
    "\t\t#The PLHEADER (one SLOT of 90 symbols) shall be composed of the following fields:\n",
    "\n",
    "\t\tprint(\"inside produce_PLHEADER method\")\n",
    "\t\t\n",
    "\t\t#* SOF (26 symbols), identifying the Start of Frame.\n",
    "\t\t#SOF shall correspond to the sequence 18D2E82 HEX \n",
    "\t\t#(01-1000-....-0010 in binary notation, the left-side bit being the MSB of the PLHEADER).\n",
    "\t\tSOF = BitArray('0b 01 1000 1101 0010 1110 1000 0010')\n",
    "\t\t\n",
    "\t\t#doing it wrong\n",
    "\t\t#here's a better way\n",
    "\t\t#a = np.array([[1,  0],\n",
    "\t\t#               [1,  1],\n",
    "\t\t#               [0,  1]], dtype=bool)\n",
    "\t\t#b = np.array([[1,  1,  0],\n",
    "\t\t#               [0,  1,  1]], dtype=bool)\n",
    "     #\n",
    "\t\t#print(np.dot(a,b)\n",
    "\t\t#to see 0's and 1's simply multiply with 1\n",
    "\n",
    "\t\t#print(1*np.dot(a,b)\n",
    "\t\t#Answer is\n",
    "\n",
    "\t\t#[[1 1 0]\n",
    "\t\t# [1 1 1]\n",
    "\t\t# [0 1 1]]\n",
    "\t\t\n",
    "\t\t#* PLS code (64 symbol): PLS (Physical Layer Signalling) code shall be \n",
    "\t\t#a non-systematic binary code of length 64 and dimension 7 with minimum distance dmin = 32. \n",
    "\t\t#It is equivalent to the first order Reed-Muller under permutation. \n",
    "\t\t#It transmits 7 bits for physical layer signalling purpose. \n",
    "\t\t#These 7 bits consists of two fields: MODCOD and TYPE defined as follows:\n",
    "\t\t#- MODCOD (5 symbols), identifying the XFECFRAME modulation and FEC rate;\n",
    "\t\t#G = array([[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],\n",
    "\t\t#[0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1],\n",
    "\t\t#[0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1],\n",
    "\t\t#[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1],\n",
    "\t\t#[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],\n",
    "\t\t#[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]], dtype=bool)\n",
    "        \n",
    "        \n",
    "\t\tG = array([[0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1],\n",
    "\t\t[0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1],\n",
    "\t\t[0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1,0,0,0,0,1,1,1,1],\n",
    "\t\t[0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1],\n",
    "\t\t[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],\n",
    "\t\t[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]], dtype=bool)\n",
    "\t\t\n",
    "\t\t\n",
    "\t\tprint(\"the modulation is\", XFECFRAME_modulation)\n",
    "\t\tprint(\"the code rate is\", FEC_rate)\n",
    "\t\t\n",
    "\t\tMODCOD = array([1,1,1,1,1,1], dtype=bool)\n",
    "\t\t\n",
    "\t\t#print(G\n",
    "\t\tprint(MODCOD.astype(int))\n",
    "\t\t\n",
    "\t\t#yes this is pedantic and typed out at length. I had issues.\n",
    "\t\t\n",
    "\t\tMODCOD = array([0,0,0,0,0,0], dtype=bool)\n",
    "\t\tprint(\"dummy PLFRAME normal size\", matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,0,0,1], dtype=bool)\n",
    "\t\tprint(\"dummy PLFRAME short size\", matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,0,1,0], dtype=bool)\n",
    "\t\tprint(\"QPSK 1/4 PLFRAME normal size\", matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,0,1,1], dtype=bool)\n",
    "\t\tprint(\"QPSK 1/3 PLFRAME short size\", matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,1,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,0,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,0,1,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,1,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,0,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,1,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([0,1,1,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,1,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,0,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,0,1,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,1,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,0,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,0,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,0,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,0,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,0,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,1,0,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,1,0,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,1,1,0], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\t\tMODCOD = array([1,1,1,1,1,1], dtype=bool)\n",
    "\t\tprint(matmul(MODCOD, G).astype(int))\n",
    "\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "\t\tMODCOD = array([0,0,0,0,1,0], dtype=bool)\n",
    "\t\t\n",
    "\t\tcodeword = matmul(MODCOD, G)\n",
    "\t\tprint(\"the codeword is a boolean array\", codeword)\n",
    "\n",
    "\t\tcodeword_int = codeword.astype(int)\n",
    "\t\tprint(\"the codeword as array type int\", codeword_int)\n",
    "\t\t\n",
    "\t\tcodeword_int_list = codeword_int.tolist()\n",
    "\t\tprint(\"the codeword is array type int but as a list\", codeword_int_list)\n",
    "\t\t\n",
    "\t\tcodeword_bitarray = BitArray()\n",
    "\t\t\n",
    "\t\tfor i in range(0, 32):\n",
    "\t\t\t#print(\"this is element\", (codeword_int_list[0][i]))\n",
    "\t\t\tcodeword_bitarray.append([codeword_int_list[0][i]])\n",
    "\t\t\n",
    "\t\tprint(\"codeword_bitarray is\", codeword_bitarray)\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t#print(((MODCODbin*Gbin).astype(int)).tolist()\n",
    "\t\t\n",
    "\t\t\n",
    "\t\t#- TYPE (2 symbols), identifying the FECFRAME length (64 800 bits or 16 200 bits) \n",
    "\t\t#     and the presence/absence of pilots.\n",
    "\t\t#The MSB of the TYPE field shall identify 2 FECFRAME sizes \n",
    "\t\t#(0 = normal: 64 800 bits; 1 = short: 16 200 bits). \n",
    "\t\t#The LSB of the TYPE field shall identify the pilot configurations (see clause 5.5.3) \n",
    "\t\t#(0 = no pilots, 1 = pilots).\n",
    "\t\t\n",
    "\t\tprint(\"FECFRAME_length is \", FECFRAME_length)\n",
    "\t\tprint(\"pilots is \", pilots)\n",
    "\t\tif FECFRAME_length == 'normal' and pilots == 'no':\n",
    "\t\t\tTYPE = BitArray('0b 00')\n",
    "\t\t\t#print(\"normal and no\")\n",
    "\t\t\treturn(\"SOF=\"+SOF.bin+\"MODCOD=\"+codeword_bitarray.bin+\"TYPE=\"+TYPE.bin)\n",
    "\t\tif FECFRAME_length == 'normal' and pilots == 'yes':\n",
    "\t\t\tTYPE = BitArray('0b 01')\n",
    "\t\t\t#print(\"normal and yes\")\n",
    "\t\t\treturn(\"SOF=\"+SOF.bin+\"MODCOD=\"+codeword_bitarray.bin+\"TYPE=\"+TYPE.bin)\n",
    "\t\tif FECFRAME_length == 'short' and pilots == 'no':\n",
    "\t\t\tTYPE = BitArray('0b 10')\n",
    "\t\t\t#print(\"short and no\")\n",
    "\t\t\treturn(\"SOF=\"+SOF.bin+\"MODCOD=\"+codeword_bitarray.bin+\"TYPE=\"+TYPE.bin)\n",
    "\t\tif FECFRAME_length == 'short' and pilots == 'yes':\n",
    "\t\t\tTYPE = BitArray('0b 11')\n",
    "\t\t\t#print(\"short and yes\")\n",
    "\t\t\treturn(\"SOF=\"+SOF.bin+\"MODCOD=\"+codeword_bitarray.bin+\"TYPE=\"+TYPE.bin)\n",
    "\t\telse:\n",
    "\t\t\tTYPE = BitArray(None)\n",
    "\t\t\t#print(\"didn't match\")\n",
    "\t\t\treturn(\"SOF=\"+SOF.bin+\"MODCOD=\"+codeword_bitarray.bin+\"TYPE=\"+\"Invalid Result\")\n",
    "\n",
    "\n",
    "\t\t#The PLHEADER, represented by the binary sequence (y1, y2,...y90) shall be modulated \n",
    "\t\t#into 90 pi/2BPSK symbols according to the rule:\n",
    "\t\t#I.2i-1 = Q.2i-1 = (1/square root of 2) (1-2y2i-1), \n",
    "\t\t#I.2i = - Q.2i = - (1/square root of 2) (1-2y2i) for i = 1, 2, ..., 45\n",
    "\n",
    "\t\t\n",
    "\t\t\n",
    "#ActionItem: The testbench below should be in another file, eventually, or soon\t\t\n",
    "\t\t\n",
    "\t\t\n",
    "a = GSE()\n",
    "print(\"GSE data is\", a.data)\n",
    "print(\"GSE data size is\", a.size)\n",
    "\n",
    "\n",
    "b = EPU_manager()\n",
    "#print(b\n",
    "b.produce_BBFRAME()\n",
    "PLHEADER = b.produce_PLHEADER('short','yes', 'qpsk', '1/4')\n",
    "print(\"The PLHEADER is\",PLHEADER)\n",
    "b.randomize_PLFRAME()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1aae9823",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4e2875bb",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
